import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

/// custom_text_widget.dart
///
/// Created by fuchuanwei on Thu Apr 27 2023.
///
/// Description:自定义文本组件 支持前后图标(SVG)
///
class CustomTextWidget extends StatelessWidget {
  const CustomTextWidget(
      {super.key,
      this.prefixIcon,
      this.suffixIcon,
      this.size,
      this.color,
      this.textStyle,
      required this.text,
      this.space});

  ///前置图标
  final String? prefixIcon;

  ///后置图标
  final String? suffixIcon;

  ///图标尺寸
  final double? size;

  ///图标颜色
  final Color? color;

  ///文本样式
  final TextStyle? textStyle;

  ///文本内容
  final String text;

  ///间距
  final double? space;

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        if (prefixIcon != null)
          SvgPicture.asset(
            prefixIcon!,
            width: size ?? 12,
            colorFilter: color != null
                ? ColorFilter.mode(
                    color!,
                    BlendMode.srcIn,
                  )
                : null,
          ),
        SizedBox(width: space ?? 3.0),
        Text(
          text,
          style: textStyle ??
              TextStyle(
                fontSize: 14,
                color: Color(0xFF333333),
              ),
        ),
        SizedBox(width: space ?? 3.0),
        if (suffixIcon != null)
          SvgPicture.asset(
            suffixIcon!,
            width: size ?? 12,
            colorFilter: color != null
                ? ColorFilter.mode(
                    color!,
                    BlendMode.srcIn,
                  )
                : null,
          ),
      ],
    );
  }
}
